package springboot.test15.actuator;

import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.Status;
import org.springframework.stereotype.Component;


import java.util.HashMap;
import java.util.Map;

@Component
public class MyHealthIndicator extends AbstractHealthIndicator {

    private static final String VERSION = "v1.0.0";
    /**
     * 真实的检查方法
     */
    @Override
    protected void doHealthCheck(Health.Builder builder) throws Exception {
        Map<String,Object> map = new HashMap<>();
        int code = check();
        if (code != 0) {
            map.put("error","连接超时");
            map.put("ms",3000);
            builder.status(Status.DOWN).withDetail("version", VERSION);
        }
        else{
            map.put("count",1);
            map.put("ms",100);
            builder.status(Status.UP).withDetail("version", VERSION);
        }

        builder.withDetail("code",100)
                .withDetails(map);
    }

    private int check() {
        return 0;
    }
}

